﻿using Common;
using Common.Communications;
using Common.Model;
using RcsService.ParaModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RcsService.ApiServices
{
    /// <summary>
    /// 生成任务单 API服务调用
    /// </summary>
    public class ComRcsApiService
    {
        public HttpCommunication HttpCommunication { get;set; }

        private string CreatUri(RcsServiceSettingModel baseComInfo,string actionName)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(ConstString.HttpComPara);
            sb.Append(baseComInfo.Ip);
            sb.Append(ConstString.Colon);
            sb.Append(baseComInfo.Port);
            sb.Append(ConstString.HkRcsRoute);
            sb.Append(actionName);
            string uri = sb.ToString();
            return uri;
        }

        public async Task<string> RcsApiProcess(string msg, RcsServiceSettingModel baseComInfo,string actionName)
        {
            string apiResultData;
            using (HttpCommunication = new HttpCommunication())
            {
                var uri = CreatUri(baseComInfo, actionName);
                apiResultData = await HttpCommunication.PostAsync(uri, msg);
            }

            return apiResultData;
        }
    }
}
